package com.it.od.od2024.od20240203;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Collectors;

/**
 * @author: liminghui
 * @date: 2024/2/3 14:48
 * @version: 1.0
 * @description: 输入:
 * 2 8 3 7 3 6 3 5 4 4 5 3 6 2 7 3 8 4 7 5
 * 1、所有数字以空格分隔，每两个数字一组，第一个数字是行号，第二个数字是列号；
 * 2、行号和列号范围为[0,64)，用例输入保证不会越界，考生不必检查；
 * 3、输入数据至少包含两个坐标点。
 * 输出:
 * 2 8 3 7 3 5 6 2 8 4 7 5
 * 压缩后的最简化坐标列表，和输入数据的格式相同。
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<int[]> points = new ArrayList<>();
        List<Integer> list = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        for (int i = 0; i < list.size(); i += 2) {
            points.add(new int[]{list.get(i), list.get(i + 1)});
        }
        List<int[]> simplePoints = simplify(points);

        StringJoiner sj = new StringJoiner(" ");
        for (int[] simplePoint : simplePoints) {
            sj.add(simplePoint[0] + " " + simplePoint[1]);
        }
        System.out.println(sj.toString());

    }

    public static List<int[]> simplify(List<int[]> points) {
        if (points.size() < 2) {
            return points;
        }
        List<int[]> result = new ArrayList<>();
        result.add(points.get(0));
        //检查每一段与前一段斜率是否相同;
        for (int i = 1; i < points.size() - 1; i++) {
            int[] pre = points.get(i - 1);
            int[] cur = points.get(i);
            int[] next = points.get(i + 1);
            // 内ji是否相同
            if (((next[1] - cur[1]) * (cur[0] - pre[0])) != ((next[0] - cur[0]) * (cur[1] - pre[1]))) {
                result.add(cur);
            }
        }
        result.add(points.get(points.size() - 1));
        return result;
    }
}
